﻿package com.tudou.utils
{
    import flash.events.*;
    import flash.net.*;

    public class URLLoaderUtil extends Object
    {

        public function URLLoaderUtil()
        {
            return;
        }// end function

        public static function newIt(param1:URLLoader, param2:Function, param3:Function = null, param4:Function = null, param5:Function = null) : URLLoader
        {
            param1 = deleteIt(param1, param2, param3, param4, param5);
            param1 = new URLLoader();
            if (param2 != null)
            {
                param1.addEventListener(Event.COMPLETE, param2);
            }
            if (param3 != null)
            {
                param1.addEventListener(SecurityErrorEvent.SECURITY_ERROR, param3);
            }
            if (param4 != null)
            {
                param1.addEventListener(IOErrorEvent.IO_ERROR, param4);
            }
            if (param5 != null)
            {
                param1.addEventListener(HTTPStatusEvent.HTTP_STATUS, param5);
            }
            return param1;
        }// end function

        public static function deleteIt(param1:URLLoader, param2:Function, param3:Function = null, param4:Function = null, param5:Function = null) : URLLoader
        {
            if (param1)
            {
                if (param2 != null)
                {
                    param1.removeEventListener(Event.COMPLETE, param2);
                }
                if (param3 != null)
                {
                    param1.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, param3);
                }
                if (param4 != null)
                {
                    param1.removeEventListener(IOErrorEvent.IO_ERROR, param4);
                }
                if (param5 != null)
                {
                    param1.removeEventListener(HTTPStatusEvent.HTTP_STATUS, param5);
                }
                param1 = null;
            }
            return param1;
        }// end function

    }
}
